import json
import logging

import requests


class getHttp:
    def __init__(self):
        self.session = requests.Session()

    def getHttp(self, method, url, data, headers={"Content-Type": "application/json"}):
        try:
            if method.upper() == "POST":
                result = self.session.post(url=url, data=data, headers={"Content-Type": "application/x-www-form-urlencoded"})
                result_time = result.elapsed.total_seconds()
                # print(result.text, result_time)
                return result, result_time
            elif method.upper() == "GET":
                result = self.session.get(url=url, params=data, headers=headers)
                result_time = result.elapsed.total_seconds()
                # print(result.text, result_time)
                return result, result_time
            else:
                print("请求方式错误")
        except Exception as e:
            print("请求错误".format(e))



